local kl__xiongluan = fk.CreateSkill{
  name = "kl__xiongluan",
  tags = {Skill.Limited,},
}

kl__xiongluan:addEffect("active", {
  prompt = function(self, player, cards, targets)
    if player:usedSkillTimes(kl__xiongluan.name,Player.HistoryGame) == 0 then
      return "#kl__xiongluan"
    else
      return "将你的所有装备牌当普通【杀】使用"
    end
  end,
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    if player:usedSkillTimes(kl__xiongluan.name,Player.HistoryGame) == 0 then
      return true
    else
      return #table.filter(player:getCardIds("h"), function(id)
        local card = Fk:getCardById(id)
        return card.type == Card.TypeEquip
      end) > 0 and player:getMark("@@kl__xiongluan_active-turn") > 0
    end
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    if player:usedSkillTimes(kl__xiongluan.name,Player.HistoryGame) == 0 then
      return to_select ~= player
    else
      local card = Fk:cloneCard("slash")
      return to_select ~= player and player:canUseTo(card, to_select)
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if player:getMark("@@kl__xiongluan_active-turn") == 0 then
      room:abortPlayerArea(player, {Player.JudgeSlot,Player.TreasureSlot})
      local slots = player:getAvailableEquipSlots()
      local choice = room:askToChoices(player, {
        choices = slots,
        min_num = 0,
        max_num = #slots,
        skill_name = kl__xiongluan.name,
        prompt = "#kl__xiongluan-abort",
        cancelable = false,
      })
      room:abortPlayerArea(player, choice)
      local n = #choice
      room:addPlayerMark(target, "@@kl__xiongluan_distances-turn",1)
      room:addTableMarkIfNeed(player, "kl__xiongluan_distances-turn", target.id)
      if n > 0 then
        room:addPlayerMark(target, "@@kl__xiongluan_times-turn",1)
        room:addTableMarkIfNeed(player, "kl__xiongluan_times-turn", target.id)
      end
      if n > 1 then
        room:addPlayerMark(player, "@@kl__xiongluan_slash-turn",1)
      end
      if n > 2 then
        room:addPlayerMark(target, "@@kl__xiongluan_prohibit-turn",1)
      end
      if n > 3 then
        room:addPlayerMark(player, "@@kl__xiongluan_active-turn",1)
      end
    else
      local cards = table.filter(player:getCardIds("h"), function(id)
        local card = Fk:getCardById(id)
        return card.type == Card.TypeEquip
      end)
      room:askToUseVirtualCard(player, {
        name = "slash",
        subcards = cards,
        skill_name = kl__xiongluan.name,
        cancelable = false,
        extra_data = {
          must_targets = { target.id },
        },
      })
      room:setPlayerMark(player, "@@kl__xiongluan_active-turn", 0)
    end
  end,
})

kl__xiongluan:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    if player:getMark("@@kl__xiongluan_prohibit-turn") > 0 then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds("h"), id)
      end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@kl__xiongluan_prohibit-turn") > 0 then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds("h"), id)
      end)
    end
  end,
})

kl__xiongluan:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card, to)
    return card and to and table.contains(player:getTableMark("kl__xiongluan_times-turn"), to.id)
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and to and table.contains(player:getTableMark("kl__xiongluan_distances-turn"), to.id)
  end,
})

kl__xiongluan:addEffect(fk.TargetSpecified, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kl__xiongluan.name) and player:getMark("@@kl__xiongluan_slash-turn") > 0 and data.card and
    data.card.trueName == "slash" and data.to:getMark("@@kl__xiongluan_distances-turn") > 0 and #data.to:getEquipments(Card.SubtypeArmor) > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = kl__xiongluan.name,
      prompt = "#kl__xiongluan-invoke::" .. data.to.id .. ":" .. data.card:toLogString(),
    })
  end,
  on_use = function(self, event, target, player, data)
    data.to:addQinggangTag(data)
  end,
})



return kl__xiongluan
